local jieyi = fk.CreateSkill {

  name = "joyex__jieyi",

  tags = {  },

}



jieyi:addEffect("active", {
  name = "joyex__jieyi",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#joyex__jieyi",
  can_use = function(self, player)
    return player:usedSkillTimes(jieyi.name) == 0 and not player:isNude()
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, player, to_select, selected)
    if #selected == 0 and to_select ~= player and #selected_cards == 1 then
      if Fk:currentRoom():getCardArea(selected_cards[1]) == Player.Hand then
        return true
      else
        local target = Fk:currentRoom():getPlayerById(to_select)
        local card = Fk:getCardById(selected_cards[1])
        return #target:getAvailableEquipSlots(card.sub_type) > 0
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if room:getCardArea(effect.cards[1]) == Player.Hand then
      room:obtainCard(target, effect.cards[1], false, fk.ReasonGive)
    else
      room:moveCards({
        ids = effect.cards,
        from = effect.from,
        to = effect.tos[1],
        toArea = Card.PlayerEquip,
        skillName = jieyi.name,
        moveReason = fk.ReasonPut,
      })
    end
    if player.dead then return end
    if player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = jieyi.name
      })
    end
    player:drawCards(1, jieyi.name)
    if player.dead or target.dead then return end
    if target.hp < player.hp and room:askForSkillInvoke(player, jieyi.name, nil, "#joyex__jieyi-invoke1::"..target.id) then
      room:doIndicate(player.id, {target.id})
      if target:isWounded() then
        room:recover({
          who = target,
          num = 1,
          recoverBy = player,
          skillName = jieyi.name
        })
      end
    elseif target.hp >= player.hp and not target.dead and room:askForSkillInvoke(player, jieyi.name, nil, "#joyex__jieyi-invoke2::"..target.id) then
      target:drawCards(1,jieyi.name)
    end
  end,
})

return jieyi